|
|
|
|
|
|
|
Listing 20.5 APIDEMO.ZIPSystemParametersInfo Can Set the Windows Background |
|
|
|
|
|
|
|
|
Public Const SPIF_UPDATEINIFILE = &H1
Public Const SPIF_SENDWININICHANGE = &H2
Public Const SPI_SETDESKWALLPAPER = 20
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam _
As Any, ByVal fuWinIni As Long) As Long
Sub ClearWallpaper()
Dim lRetVal As Long
lRetVal = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, "(None)", _
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub
Sub SetWallPaper(sBitmapFile As String)
Dim lRetVal As Long
lRetVal = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, sBitmapFile, _
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub |
|
|
|
|
|
|
|
|
The SetWallpaper and ClearWallpaper functions cause the Windows wallpaper bitmap to change immediately. The constants in the last parameter of the API call, although not necessary, cause any changes to be reflected in the Control Panel. If you peruse the API text file, you'll notice that you can control many additional display options with the SystemParametersInfo function. |
|
|
|
|
|
|
|
|
Finding and Controlling Other Windows |
|
|
|
|
|
|
|
|
You can control window behavior and find out information about other windows with several API calls. Most of these API calls use the window handle to identify the window to which you are referring. A window handle is simply a unique number assigned to each window currently running on your system. In Visual Basic programs, the window handle is available to the hwnd property of a form. However, if you want to manipulate a window outside your Visual Basic program, you have to first use API calls to obtain its handle. |
|
|
|
|
|
|
|
|
|
In this section, I break temporarily from my l prefix naming convention for long variables. Window handles are understood to be long, and the API declarations typically refer to them as hwnd.  |
|
|
|
|
|
|
|
|
|
|
To find the handle of a window, you can use the FindWindow API function. It has two parameters: the Window Name and the Window Class name. You can supply one or both parameters to FindWindow, and it will return the window handle or zero if no matching window exists. |
|
|
|
|
|